/**
 * Copyright (C), 2020-2021 by colley.ma
 * File Name: LockEntry.java
 * Encoding: UTF-8
 * Date: 2021年12月28日 下午12:21:46
 * History:
 */
package com.swak.frame.lock;

import com.swak.frame.dto.base.DTO;
import com.swak.frame.timer.Timeout;

public class LockEntry implements DTO {
    private static final long serialVersionUID = -717350763273004185L;

    private ScriptTag scriptTag;

    private String lockKey;

    private String requestId;

    private String script;

    private Timeout timeout;

    public LockEntry() {}

    public LockEntry(String lockKey, String requestId) {
        this.lockKey = lockKey;
        this.requestId = requestId;
    }

    public static LockEntry renewal(String lockKey, String requestId, String script) {
        LockEntry lockEntry = new LockEntry(lockKey, requestId);
        lockEntry.setScriptTag(ScriptTag.RENEWAL);
        lockEntry.setScript(script);
        return lockEntry;
    }

    public static LockEntry unlock(String lockKey, String requestId, String script) {
        LockEntry lockEntry = new LockEntry(lockKey, requestId);
        lockEntry.setScriptTag(ScriptTag.UNLOCK);
        lockEntry.setScript(script);
        return lockEntry;
    }

    public ScriptTag getScriptTag() {
        return scriptTag;
    }

    public void setScriptTag(ScriptTag scriptTag) {
        this.scriptTag = scriptTag;
    }

    public String getLockKey() {
        return lockKey;
    }

    public void setLockKey(String lockKey) {
        this.lockKey = lockKey;
    }

    public String getRequestId() {
        return requestId;
    }

    public void setRequestId(String requestId) {
        this.requestId = requestId;
    }

    public String getScript() {
        return script;
    }

    public void setScript(String script) {
        this.script = script;
    }

    public Timeout getTimeout() {
        return timeout;
    }

    public void setTimeout(Timeout timeout) {
        this.timeout = timeout;
    }

    public static enum ScriptTag {
        RENEWAL, UNLOCK;
    }
}
